home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio.more / USeqApp-app.cpp < prev    next >
Text File  |  1996-07-05  |  47KB  |  1,789 lines

  1. // USeqApp.app.p 
  2. // d.g.gilbert, 1991 
  3.  
  4.  
  5. #ifndef __Picker__
  6. #include <Picker.h>
  7. #endif
  8.  
  9. #ifndef __UDrawingEnvironment__
  10. #include <UDrawingEnvironment.h>
  11. #endif
  12. USES
  13.     UFloatWindow();
  14.  
  15. CONST
  16.         
  17.             // when do I died?
  18.     expireYear     == 1994;
  19.     expireMonth == 7; //jan=1
  20.     expireDay        == 1;    
  21.  
  22.     kAppPrefsFile == 'SeqApp Prefs';
  23.     kHelpFile == 'SeqApp.Help';
  24.     kHelpFileID    == 2402;
  25.     
  26.     cNewText  == 11;     //new plain text
  27.     cNewProj    == 12;     //new project list
  28.     cNewDebug == 14;
  29.     cNewGopher == 15;
  30.  
  31.     cOpenText    == 21;     //Open plain text
  32.     cOpenProj    == 22;     //Open project list
  33.     cOpenHelp    == 24;
  34.     cOpenGopher == 25;
  35.     cOpenTree == 26;
  36.     cOpenAAColors == 27;
  37.     cOpenNAColors == 28;
  38.  
  39.     mSequence    == 20;   //sequence menu
  40.     cNewSeq     == 2001;
  41.     cEditSeq    == 2002;
  42.     cAlnSeqs    == 2003;
  43.     cAutoAlign= 2004;
  44.     cPrettyPrint= 2005;
  45.     cDottyPlot= 2015;
  46.     cHelpCommand=4321;
  47.     
  48.     //UText has reserved c1000..c1999, hasn't yet used c1900...
  49.     //use these nums for menu buzz words
  50.     cCutSeq                == 1903;
  51.     cCopySeq            == 1904;
  52.     cPasteSeq         == 1905;
  53.     cClearSeq         == 1906;
  54.     cCutText            == 1913;
  55.     cCopyText            == 1914;
  56.     cClearText        == 1916;
  57.     cStandardCut    == 1923;
  58.     cStandardCopy    == 1924;
  59.     cStandardClear= 1926;
  60.     
  61.     cReverseSeq        == 2006;
  62.     cComplementSeq == 2007;
  63.     cTranslateSeq == 2008;
  64.     cDna2Rna == 2009;
  65.     cRna2Dna == 2010;
  66.     cSeqChange == 2000;
  67.     cRestrictMap    == 2011;
  68.     cConsensus == 2012;
  69.     cCompress == 2013;
  70.     cRevComplement == 2014;
  71.     cLockIndels        ==    2016;
  72.     cUnlockIndels    == 2017;
  73.     cSaveSelection= 2018;
  74.     
  75.     cIUBcodes    == 2402;
  76.     cAAcodes    == 2403;
  77.     cPrefsDialog == 2404;
  78.     
  79.     mChildren == 30;
  80.     cAddChildCmd == 3001;
  81.     cRemoveChildCmd == 3002;
  82.     cChildDied == 2999;
  83.     //-    kNewChildTemplateID == 3001;
  84.     
  85.     cCheckMail=    2102;
  86.     cSendMail    ==    2103;
  87.     cFileTransfer    == 2104;
  88.     cGBFetch    == 2105;
  89.     cBugMail    == 2106;
  90.     cEMBLFetch    == 2107;
  91.     cMailPref == 2108;
  92.  
  93.     cGBFasta == 2110;
  94.     cGBSearch    ==    cGBFasta;
  95.     cGBBlast    == 2111;
  96.     cGeneidSearch == 2112;
  97.     cGrailSearch == 2113;
  98.     cUHServer == 2114;
  99.     cGenmarkSearch == 2118;
  100.     cBlocksSearch == 2119;
  101.     cPythiaSearch == 2120;
  102.  
  103.     cGopher == 2201;
  104.     cGopherPrefs == 2203;
  105.     
  106.     kIUBcodeWindID == 2402;
  107.     kAAcodeWindID == 2403;
  108.     kPrefsDialogID == 2404;
  109.  
  110.     kEditOnly == TRUE;
  111.     prefMyMailAddress == 100;
  112.     kNoAddress == 'put.your&internet.address.here';
  113.  
  114.     kMacdrawHeaderSize == 512;
  115.     
  116.     msgMyError == 0x80001234;
  117.  
  118.     kSeqEdWindID        == 1006;                 // seq1ed 'view' template for a window 
  119.     // kSeqEdDocID            == 1009;  unused, seq1ed 'view' template for a window 
  120.     kAlnViewID             == 1009;
  121.     kAlnWindID            == 1010;                 // aln 'view' template for a window 
  122.     kAlnTEViewID         == 1011;                    // aln 'teview' template
  123.     kAlnAColorID        == 1012;                    // A color 
  124.     kAlnCcolorID        == 1013;
  125.     kAlnGcolorID        == 1014;
  126.     kAlnTcolorID        == 1015;
  127.     kAlnNcolorID        == 1016;
  128.  
  129.     kGray50ID        == 1026;             
  130.     kGray25ID        == 1027;             
  131.     kGray75ID        == 1028;             
  132.     
  133.     
  134.     kPrintNucStyle    == 1023;
  135.     kPrintNameStyle    == 1024;
  136.     kPrintZymeStyle == 1025;
  137.     kPrintClipType == 'PICT';
  138.  
  139.     kColorIconID        == 1001;
  140.     kMonoIconID            == 1002;
  141.     kLockIconID         == 1010;
  142.     kUnlockIconID        == 1011;
  143.     
  144.     kSeqFileType        == 'TEXT';                // uses standard text files 
  145.     kSeqedViewType     == 'TEVW';
  146.     kAlnViewType         == 'ALNV';
  147.     kAlnScrapType     ==  kAlnViewType;            // Scrap == TAlnView type 
  148.     
  149.     kMovableModalWindProc == 5;  //wind manager proc id for movable modal window 
  150.     
  151.     kHierDisplayedMBar    == 131;                            // Displayed menus on hier. menu system 
  152.     kNonHierDisplayedMBar == 128;                        // Displayed menus on non-hier. system 
  153.  
  154.     kHierMenuOffset     == 1000;                         /* Offset added to non-hier menu cmds to get
  155.                                                           the right number */
  156.     
  157.     // The 'File is too large' alert 
  158.     kFileTooBig         == 1000;
  159.  
  160.     // Constants for the text specs resource 
  161.     kTextSpecsRsrcType    == 'SPEC';
  162.     kTextSpecsRsrcID    == 1;
  163.  
  164.     // Constants for the text style resource 
  165.     kTextStyleRsrcType    == 'STYL';     //!not same as 'styl' == STScrapHandle!
  166.     kStylesRsrcID        == 1;
  167.     kElementsRsrcID     == 2;
  168.  
  169.     kNoAction    == 0;
  170.     kOpenSeqFile    == 1;
  171.     kOpenTextFile    == 2;
  172.     kOpenFile    == 3;
  173.  
  174.     
  175. TYPE
  176.  
  177.         TIUBWindow == OBJECT(TPrefWindow)
  178.             pascal void TIUBWindow::SetPrefID(void) // override 
  179.             }
  180.             
  181.         TAAWindow == OBJECT(TPrefWindow)
  182.             pascal void TAAWindow::SetPrefID(void) // override 
  183.             }
  184.  
  185.  
  186. CONST
  187.     kAAColorView == 1051;
  188.     kNAColorView == 1050;
  189.     kAAColorType == 'AClr';
  190.     kNAColorType == 'NClr';
  191.     
  192. TYPE
  193.  
  194.     colorsArray == array [' '..'~'] of RGBColor;
  195.     IDsArray == array [' '..'~'] of OSType;
  196.  
  197.     TColorPrefWind            == OBJECT (TWindow) //? TFloatWindow or plain  ?
  198.         pascal void TColorPrefWind::DoEvent(EventNumber eventNumber, 
  199.                                             TEventHandler        source; TEvent event) // override 
  200.         }
  201.                             
  202.     TColorText    == OBJECT(TStaticText)
  203.         pascal void TColorText::InstallColor(RGBColor theColor, Boolean redraw) // override 
  204.         }
  205.  
  206.     TColorPrefDocument        == OBJECT (TFileBasedDocument)
  207.         fBaseKind    : integer;
  208.         fWindID        : integer;
  209.         fColorPrefWind    : TColorPrefWind;
  210.         fSwapBackground    : TCheckBox;
  211.         fColors        : colorsArray;
  212.         fViewIDs    : IDsArray;
  213.         Boolean        fDoSetGlobals;
  214.         fSwapBack    : Boolean;
  215.         Str255        fDescription;
  216.         
  217.         pascal void TColorPrefDocument::IColorPrefDocument( TFile itsFile, Integer baseKind)
  218.         pascal void TColorPrefDocument::Free(void) // override 
  219.         pascal void TColorPrefDocument::FreeData(void) // override 
  220.         pascal void TColorPrefDocument::Close(void) /* override */ 
  221.  
  222.         pascal void TColorPrefDocument::SetGlobals(void) 
  223.         pascal void TColorPrefDocument::DoHitLetter(TStaticText theLet)
  224.         pascal void TColorPrefDocument::DoMakeViews(Boolean forPrinting) // override 
  225.         pascal void TColorPrefDocument::UntitledName(Str255 VAR noName) // override 
  226.         pascal TFile TColorPrefDocument::DoMakeFile(CommandNumber itsCommandNumber) // override 
  227.         pascal void TColorPrefDocument::DoNeedDiskSpace(TFile itsFile,
  228.                                                             long VAR dataForkBytes, rsrcForkBytes) // override 
  229.         pascal void TColorPrefDocument::DoRead(aFile:TFile; Boolean forPrinting) // override 
  230.         pascal void TColorPrefDocument::DoWrite(TFile aFile, Boolean makingCopy) // override 
  231.         }
  232.     
  233. VAR
  234.     gNoColor    : RGBColor;
  235.     gNoViewID    : OSType;
  236.     colorsArray        gAAcolors, gNAcolors;
  237.     Boolean        gSwapBackground;
  238.     
  239.         
  240.  
  241. VAR 
  242.     gDefWordBreak            : procPtr;    
  243.     gDefTEDrawHook        : procPtr;
  244.     gDefTEHitTestHook    : procPtr;
  245.     
  246.     gAlnStyle            : TextStyle;
  247.     integer        gAlnCharWidth ;
  248.     gMachineType    : Integer; 
  249.     gGoodMac                : Boolean; //temp test Mac SE bombs 
  250.     
  251. //-    gChildList         : TList; 
  252.  
  253.     gActiveAlnDoc    : TAlnDoc;
  254.     Handle        gLockIcon, gUnLockIcon;  
  255.     gHelpFile        : StringHandle;
  256.  
  257.  
  258.  
  259.  
  260.  
  261. #pragma segment AInit
  262.  
  263.  
  264. pascal void TSeqAppApplication::DoAppleCommand( CommandNumber aCommandNumber,
  265.                                                  AppleEvent message, reply) // override 
  266. {    
  267.             inherited::DoAppleCommand(aCommandNumber, message, reply);
  268. /*------
  269.     switch (aCommandNumber) {
  270.         case cChildDied:  
  271.             if ((noErr != HandleChildDiedEvent( message, reply, aCommandNumber))) ;
  272.             
  273.         Otherwise
  274.             inherited::DoAppleCommand(aCommandNumber, message, reply);
  275.              
  276.         }
  277. -----*/
  278. }
  279.  
  280. pascal void TSeqAppApplication::DoAboutBox(void) // override 
  281. /* Method to display the "About" box for your application.  Override to do interesting things.
  282. Since it is normally called from a command; the app usually has the maximum free space available. */
  283. CONST
  284.         kAboutID == 1000;
  285.  
  286. VAR
  287.     apRefnum, indx, len, saverez    : integer;
  288.     apParam    : Handle;
  289.     aWind    : TWindow;
  290.     aDies, aVers    : TStaticText;
  291.     IDType        dismisser ;
  292.     aStr    : Str255;
  293.     aDay    : DateTimeRec;
  294.     secs    : longint;
  295.     VersRecHndl        appVers;
  296. {
  297.     FailSpaceIsLow();
  298.     GetAppParms(aStr, apRefnum, apParam);
  299.     ParamText(aStr, '', '', '');
  300.  
  301.     aWind = TWindow(gViewServer->NewTemplateWindow(kAboutID, NULL));
  302.     FailNIL(aWind);          
  303.     aDies = TStaticText( aWind->FindSubView('DIES'));
  304.     if (aDies!=NULL) {
  305.         aDay.year= expireYear;
  306.         aDay.month= expireMonth;
  307.         aDay.day= expireDay;
  308.         aDay.hour= 1;
  309.         aDay.minute= 1;
  310.         aDay.second= 1;
  311.         Date2Secs( aDay, secs);
  312.         IUDateString( secs, abbrevDate, aStr);
  313.         aDies->SetText( aStr, kDontRedraw);
  314.         }
  315.  
  316.     //- pascal void WithApplicationResFileDo(pascal void DoWithResFile); << global proc in TApplication 
  317.     
  318.     aVers = TStaticText( aWind->FindSubView('vers'));
  319.     if (aVers!=NULL) {
  320.         saverez= CurResFile;
  321.         UseResFile(gApplicationRefNum);  
  322.         Handle(appVers)= GetResource('vers', 1);  //!this pulls from Prefs file if open
  323.         UseResFile(saverez);  
  324.         if (appVers!=NULL)) aVers->SetText((*appVers)->shortVersion, kDontRedraw);
  325.         /*--- ?? pull long vers string from record 
  326.         indx= ord((*appVers)->shortVersion[0]) + 1; 
  327.         len= (*appVers)->shortVersion[indx];
  328.         BlockMove( &(*appVers)->shortVersion[indx], &aStr[0], len);
  329.         if (appVers!=NULL)) aVers->SetText(aStr, kDontRedraw);
  330.         ---*/
  331.         }    
  332.     
  333.     /*---
  334.     aWind->ShowReverted();   
  335.     aWind->Open();  
  336.     AddWindow( aWind);
  337.     ---*/
  338.     aWind->SetModality( True); //!!! or PoseModally will fail !
  339.     dismisser= aWind->PoseModally();
  340.     aWind->CloseAndFree(); 
  341. }
  342.  
  343. pascal void TSeqAppApplication::InstallHelpMenuItems(void) // override 
  344. {
  345.     //  // gMenuBarManager->AddHelpMenuItem( "^0 Help", kYourHelpCommandNumber ); 
  346.     gMenuBarManager->AddHelpMenuItem( '^0 Help', cHelpCommand);
  347. }
  348.  
  349.  
  350. pascal void TSeqAppApplication::ISeqAppApplication(void)
  351. VAR
  352.     line        :    Str255;
  353.     aTEView    :    TTEView;
  354.     TextStyle        aTextStyle;
  355.     aColor    : RGBColor;
  356.     hTest        : Handle;
  357.     i, dirId, lnum    : longint;
  358.     err    : OSErr;
  359.     ch    : char;
  360.     
  361.     procedure getAlnStyle( RGBColor var aColor, TextStyle var aTextStyle, integer rsrcID)
  362.     TTEView        var  aTEView;
  363.             TextStyle        SaveStyle;
  364.     begin
  365.         MAGetTextStyle(rsrcID, aTextStyle); //Mapp3
  366.         aColor= aTextStyle.tsColor;
  367.         /*----
  368.         aTEView = TTEView(gViewServer->DoCreateViews(NULL, NIL, rsrcID, gZeroVPt));
  369.         FailNIL(aTEView);
  370.         aColor= aTEView->fTextStyle.tsColor;
  371.       aTextStyle = aTEView->fTextStyle;
  372.         aTEView->Free();
  373.         ----*/
  374.     end();
  375.     
  376.     pascal void ListZyme( TREnzyme aZyme)
  377.     str255        VAR  cuts, cut3s;
  378.     {
  379.         NumToString( aZyme->fCutpoint, cuts);
  380.         NumToString( aZyme->fCut3from5, cut3s);
  381.         DebugMsg(concat( aZyme->fName, '  ',cuts,' ',aZyme->fSite, ' ', cut3s, 
  382.                                 ' ! >',aZyme->fVendors));
  383.     }
  384.     
  385.  
  386.     pascal void Expire(void)
  387.         /* If date > expireDate then 
  388.                 a) change self.name to "Expired"+self.name (may fail if locked)
  389.                 b) change file type from 'APPL' to '????'  (ditto)
  390.                 c) exitToShell
  391.             --------*/
  392.         /* MacApp alert 129:
  393.             Could not complete the "^2" command because ^0. ^1
  394.             MacApp alert 130:  <<<<<<
  395.             Could not complete your request because ^0. ^1
  396.         */
  397.     VAR
  398.         apRefnum, err    : integer;
  399.         apParam        : Handle;
  400.         apName        : Str255;
  401.         today            : DateTimeRec;
  402.         fndrInfo    : fInfo;
  403.         dead, realdead            : Boolean;
  404.     {
  405.         GetTime( today);
  406.         dead= (today.year > expireYear);
  407.         dead= dead || ((today.year == expireYear) && (today.month > expireMonth));
  408.         realdead= dead;
  409.         dead= dead || ((today.year == expireYear) && (today.month == expireMonth) 
  410.                                 && (today.day >= expireDay));
  411.         
  412.         if (dead) {
  413.             GetAppParms(apName, apRefnum, apParam);
  414.             err= GetFInfo( apName, 0, fndrInfo);
  415.             if (realdead)) {
  416.                 fndrInfo.fdType= '????';
  417.                 err= SetFInfo( apName, 0, fndrInfo);
  418.                 err= Rename( apName, 0, concat('Expired ',apName));
  419.                 }
  420.             ParamText(
  421.                 concat('this release of ',apName,' has expired'),
  422.                 'Read docs or e-mail to SeqApp&Bio.Indiana.Edu.',
  423.                                         '','');    
  424.             err= Alert( 130, NULL); //<< this pulls us out of this proc??.
  425.             if (realdead)) 
  426.                 ExitToShell();
  427.             }
  428.     }
  429.     
  430. {
  431.  
  432.     Expire();
  433.     
  434.     if (gHasGestalt && (Gestalt( gestaltMachineType, lnum) == noErr))
  435.         gMachineType= lnum
  436.     else 
  437.         gMachineType= 0;
  438.     gGoodMac= !(gMachineType IN 
  439.         [gestaltClassic,gestaltMacXL,gestaltMac512KE,gestaltMacPlus,gestaltMacSE]);
  440.     
  441.     //- gConfiguration.hasColorQD= FALSE; 
  442.         
  443.     gDebugDoc= NULL;
  444.     gActiveAlnDoc= NULL;    // this one is obsolete?
  445.     gTextDocSig = kSAppSig; //??
  446.  
  447.     /*---
  448.     if (!gGoodMac) IPrefApplication(kSeqFileType,'••BadMac••') else 
  449.     ---*/
  450.     IPrefApplication(kSeqFileType,kSAppSig,kAppPrefsFile);
  451.     
  452.     gHelpFile= GetString(kHelpFileID);
  453.   if (gHelpFile=NULL) gHelpFile= NewString(kHelpFile);
  454.         
  455.     InitUFloatWindow(); //??
  456.     
  457.     InitTextGlobals();
  458.     InitializeTCP();
  459.     InitializeMailPrefs();    
  460.     InitializeUGopher();       // reads in icons, ...
  461.     InitializeGopher();
  462.     gGopherDocSig= kSAppSig;    // we want to own our gopher folders....
  463.     InitUSequence();                 //<< This reads a codon data file !?
  464.  
  465. /**** not for Mapp3 
  466.   THandleHighlevelEvents        aHandleHighlevelEvents;  
  467.     if (gHasAppleEvents) {
  468.         fLaunchWithNewDocument = FALSE;  //< turn off this damn nuisance 
  469.         NEW(aHandleHighlevelEvents);
  470.         aHandleHighlevelEvents->IEventHandler(NULL);
  471.         this->InstallCohandler( aHandleHighlevelEvents, TRUE);
  472.         }
  473. ******/        
  474.     FailOSErr(AEInstallEventHandler( kCoreEventClass, kAEApplicationDied, 
  475.                                 EventHandlerProcPtr(StripLong(&HandleChildDiedEvent)), 0, FALSE));
  476.     //^^ see DoAppleCommand instead 
  477.  
  478.         
  479.     InitChildApps( gHasAppleEvents);        /* Must call After IPrefApplication*/    
  480.  
  481.     //! DON'T USE -- Cause BOMB, MUST fetch icon hand as used?
  482.     if (gConfiguration.hasColorQD then begin
  483.         gLockIcon= Handle( GetCIcon( kLockIconID));
  484.         gUnlockIcon= Handle( GetCIcon( kUnLockIconID));
  485.         }    else {
  486.         gLockIcon= Handle( GetIcon( kLockIconID));
  487.         gUnlockIcon= Handle( GetIcon( kUnLockIconID));
  488.         }
  489.     
  490.     /*set alnseq colors from a view !*/    
  491.     
  492.     getAlnStyle( gAcolor, gAlnStyle, kAlnAColorID);  //globals are in USeqPrint
  493.     getAlnStyle( gCcolor, gAlnStyle, kAlnCColorID);
  494.     getAlnStyle( gGcolor, gAlnStyle, kAlnGColorID);
  495.     getAlnStyle( gTcolor, aTextStyle, kAlnTColorID);
  496.     getAlnStyle( gNcolor, aTextStyle, kAlnNColorID);
  497.  
  498.     gNAcolors[' ']= gRGBWhite;
  499.     for ch= '!' to '~' do gNAcolors[ch]= gNcolor;
  500.     gNAcolors['A']= gAcolor;
  501.     gNAcolors['C']= gCcolor;
  502.     gNAcolors['G']= gGcolor;
  503.     gNAcolors['T']= gTcolor;
  504.     gNAcolors['U']= gTcolor;
  505.     gNAcolors['a']= gAcolor;
  506.     gNAcolors['c']= gCcolor;
  507.     gNAcolors['g']= gGcolor;
  508.     gNAcolors['t']= gTcolor;
  509.     gNAcolors['u']= gTcolor;
  510.     BlockMove( &gNAcolors, &gAAcolors, sizeof(colorsArray));
  511.     gSwapBackground= False;
  512.     
  513.     getAlnStyle( gGray50, aTextStyle, kGray50ID);        //globals are in USeqPrint
  514.     getAlnStyle( gGray25, aTextStyle, kGray25ID);
  515.     getAlnStyle( gGray75, aTextStyle, kGray75ID);
  516.     
  517.     getAlnStyle( aColor, gPrintNucStyle, kPrintNucStyle);//globals are in USeqPrint
  518.     getAlnStyle( aColor, gPrintNameStyle, kPrintNameStyle);
  519.     getAlnStyle( aColor, gPrintZymeStyle, kPrintZymeStyle);
  520.  
  521.     gSeqListDoc= NULL;
  522.  
  523.     // Suppress dead-stripping of the following classes 
  524.     if (gDeadStripSuppression) {
  525.  
  526.          if (Member(TObject(NULL), TREMapDocument));
  527.         if (Member(TObject(NULL), TREMapWind));
  528.         if (Member(TObject(NULL), TREMapView));
  529.  
  530.         if (Member(TObject(NULL), TSeqPrintDocument));
  531.         if (Member(TObject(NULL), TSeqPrintWind));
  532.         if (Member(TObject(NULL), TSeqPrintView));
  533.  
  534.         if (Member(TObject(NULL), TAAWindow));
  535.         if (Member(TObject(NULL), TIUBWindow));
  536.         if (Member(TObject(NULL), TPrefWindow));
  537.  
  538.         if (Member(TObject(NULL), TAlnDlog));
  539.         if (Member(TObject(NULL), TAlnDoc));
  540.         
  541.         if (Member(TObject(NULL), TTreePrintView));
  542.         if (Member(TObject(NULL), TTreePrintWind));
  543.         if (Member(TObject(NULL), TTreePrintHandler));
  544.         if (Member(TObject(NULL), TTreePrintDocument));
  545.  
  546.         if (Member(TObject(NULL), TDottyPlotView));
  547.         if (Member(TObject(NULL), TDottyPlotWind));
  548.         if (Member(TObject(NULL), TDottyPlotHandler));
  549.         if (Member(TObject(NULL), TDottyPlotDocument));
  550.  
  551.         if (Member(TObject(NULL), TAlnPrintView));
  552.         if (Member(TObject(NULL), TAlnPrintWind));
  553.         if (Member(TObject(NULL), TAlnPrintDocument));
  554.  
  555.         if (Member(TObject(NULL), TColorText));
  556.         if (Member(TObject(NULL), TColorPrefWind));
  557.         if (Member(TObject(NULL), TColorPrefDocument));
  558.  
  559.         if (Member(TObject(NULL), TRCshifter));
  560.         if (Member(TObject(NULL), TAlnShifter));
  561.  
  562.         if (Member(TObject(NULL), TREnzyme));
  563.         if (Member(TObject(NULL), TREnzymeVendor));
  564.         if (Member(TObject(NULL), TREMap));
  565.         
  566.         if (Member(TObject(NULL), TSeqIndex));
  567.         if (Member(TObject(NULL), TSeqHIndex));
  568.         if (Member(TObject(NULL), TSeqedView));
  569.         if (Member(TObject(NULL), TSequence));
  570.  
  571.         if (Member(TObject(NULL), TSeqListView)); //? are we dropping this?
  572.         if (Member(TObject(NULL), TSeqListDoc));
  573.  
  574.         if (Member(TObject(NULL), TSeqedWindow));
  575.  
  576.         if (Member(TObject(NULL), TAlnSequence));
  577.         if (Member(TObject(NULL), TAlnView));
  578.         if (Member(TObject(NULL), TAlnIndex));
  579.         if (Member(TObject(NULL), TAlnHIndex));
  580.         if (Member(TObject(NULL), TAlnScroller));
  581.         if (Member(TObject(NULL), TSideScroller));
  582.         if (Member(TObject(NULL), TAlnWindow));
  583.  
  584.         if (Member(TObject(NULL), TFindDialog));
  585.         if (Member(TObject(NULL), TTextData));
  586.         if (Member(TObject(NULL), TTextView));
  587.         if (Member(TObject(NULL), TTextDocument));
  588.         }
  589.         
  590. //! Debug Text window
  591. /*========
  592.     gApplication->OpenNew(cNewDebug);
  593.  
  594.     DebugMsg('R.Enzyme Table Dump........');    
  595.     DebugMsg('Name / Site / Vendors');    
  596.     gREMap->fREnzymes->Each(listZyme);
  597. =======*/
  598. /*=========
  599.     DebugMsg('Codon Table Dump........');
  600.     DebugMsg(' AA  Codon  num/K');
  601.     for i= 1 to 64 do begin
  602.         lnum= trunc( gCodonTable[i].numPerK);
  603.         NumToString( lnum, line);
  604.         line= concat('  a  ccc   ',line);
  605.         line[3]= gCodonTable[i].amino;
  606.         line[6]= gCodonTable[i].codon[1];
  607.         line[7]= gCodonTable[i].codon[2];
  608.         line[8]= gCodonTable[i].codon[3];
  609.         DebugMsg( line);
  610.         }
  611. ===========*/
  612.  
  613. }
  614.  
  615.  
  616.  
  617.  
  618.  
  619. CONST  
  620.         kSeqSFGetDlogID == 4000;
  621.         kSeqSFGetPopupMenuID == 4000;
  622.     kSFGetText == 12;  //dlog item #
  623.         kSFGetBases == 13;
  624.         kSFGetTree == 14;
  625.         kSFGetBasesAppend == 15;
  626.         
  627. VAR
  628.         gSFGetFirst    : boolean;
  629.     gSFGetKind    : integer;
  630.         MenuHandle        gSFGetPopupMenu;
  631.         
  632.  
  633. //- pascal integer sfGetDlogHook( integer item, dialogPtr dlog) << Mapp2
  634. //! Mapp3 uses CustomGetFile which has 3rd param on sfGetDlogHook !
  635. pascal integer sfGetDlogHook( integer item, dialogPtr dlog, Ptr myDataPtr) //<< Mapp3
  636. VAR  itype: integer; controlHandle ch, box: rect; longint menuitem,
  637. {
  638.   if (gSFGetFirst || (item IN [kSFGetText..kSFGetBasesAppend])) {
  639.     if ((item IN [kSFGetText..kSFGetBasesAppend])) gSFGetKind= item;
  640.         
  641.     getDItem(dlog, kSFGetBases, itype, handle(ch), box);
  642.     setCtlValue(ch, ord(gSFGetKind=kSFGetBases));
  643.  
  644.     getDItem(dlog, kSFGetBasesAppend, itype, handle(ch), box);
  645.     setCtlValue(ch, ord(gSFGetKind=kSFGetBasesAppend));
  646.  
  647.     getDItem(dlog, kSFGetText, itype, handle(ch), box);
  648.     setCtlValue(ch, ord(gSFGetKind=kSFGetText));
  649.  
  650.     getDItem(dlog, kSFGetTree, itype, handle(ch), box);
  651.     setCtlValue(ch, ord(gSFGetKind=kSFGetTree));
  652.  
  653.         /*--
  654.     getDItem(dlog, kSFGetPopup, itype, handle(ch), box);
  655.         InsertMenu( gSFGetPopupMenu, -1);
  656.         menuitem= PopUpMenuSelect( gSFGetPopupMenu, box.top, box.left, gSFGetKind);
  657.         DeleteMenu( kSeqSFGetPopupMenuID);
  658.         gSFGetKind= LoWord( menuItem);
  659.         --*/
  660.     gSFGetFirst= FALSE;
  661.     }
  662.   SFGetDlogHook= item;
  663. } //SFGetDlogHook
  664.  
  665.  
  666. #pragma segment AOpen
  667. pascal void TSeqAppApplication::GetStandardFileParameters(CommandNumber itsCommandNumber,
  668.                                  ProcPtr        VAR fileFilter;
  669.                                  TypeListHandle        VAR typeList;
  670.                                  short        VAR dlgID;
  671.                                  Point        VAR where; VAR dlgHook,
  672.                                  ProcPtr        modalFilter;
  673.                                  Ptr        VAR activeList;
  674.                                  ProcPtr        VAR activateProc;
  675.                                  VAR yourDataPtr: UNIV Ptr); // override 
  676. VAR
  677.     integer        numTypes;
  678. {
  679.     inherited::GetStandardFileParameters( itsCommandNumber, fileFilter, typeList, 
  680.             dlgID, where, dlgHook, modalFilter, activeList, activateProc, yourDataPtr);
  681.  
  682.     dlgID= kSeqSFGetDlogID;
  683.     dlgHook= &sfGetDlogHook;
  684.     gSFGetFirst= TRUE;
  685.     gSFGetKind= kSFGetBases;
  686.     //- gSFGetPopupMenu= GetMenu( kSeqSFGetPopupMenuID);
  687.     
  688.     numTypes = GetHandleSize(Handle(typeList)) / sizeof(ResType);
  689.             //??
  690.     numTypes = numTypes + 2;
  691.     SetHandleSize(Handle(typeList), numTypes * sizeof(ResType));
  692.     (*typeList)^[numTypes-1] = kAAColorType;
  693.     (*typeList)^[numTypes] = kNAColorType;
  694.     
  695.   if (((itsCommandNumber != cOpenGopher) || optionKeyIsDown)) {
  696.         numTypes = numTypes + 1;
  697.         SetHandleSize(Handle(typeList), numTypes * sizeof(ResType));
  698.         FailMemError();
  699.         }
  700.     (*typeList)^[numTypes] = kGopherFileType;
  701. }
  702.  
  703.  
  704. pascal CommandNumber TSeqAppApplication::KindOfDocument(CommandNumber itsCommandNumber,
  705.                                              TFile itsFile) // override 
  706. VAR  aType: OSType;
  707. {
  708.     itsCommandNumber= inherited::KindOfDocument(itsCommandNumber, itsFile); 
  709.     switch (itsCommandNumber) {
  710.         cFinderNew  : itsCommandNumber= cNewProj;
  711.         cFinderPrint: itsCommandNumber= cOpenText;
  712.         cOpen, 
  713.         cFinderOpen : if (itsFile!=NULL) {
  714.             if ((itsFile->GetFileType( aType) == noErr)) {
  715.                 if ((aType == kSeqFileType)) 
  716.                     itsCommandNumber= cOpenProj
  717.                 else if ((aType == kNAColorType)) 
  718.                     itsCommandNumber= cOpenNAColors
  719.                 else if ((aType == kAAColorType)) 
  720.                     itsCommandNumber= cOpenAAColors
  721.                 else if ((aType == kGopherFileType)) 
  722.                     itsCommandNumber= cOpenGopher;
  723.                 }
  724.             }            
  725.         }
  726.     KindOfDocument= itsCommandNumber;
  727. }
  728.  
  729.  
  730.  
  731. pascal Boolean TSeqAppApplication::TestForSeqFile(TFile aFile)
  732. VAR
  733.         integer        fref, rezref, format;
  734.         OSType        maker;
  735. {
  736.     if ((aFile->GetFileCreator( maker) == noErr) && (maker == kSAppSig)) 
  737.         TestForSeqFile= TRUE 
  738.     else {
  739.         FailOSErr(aFile->OpenFile());
  740.         format= SeqFileFormatWrapper( aFile->fDataRefNum, FALSE);
  741.         FailOSErr(aFile->CloseFile());
  742.         TestForSeqFile= (format != kUnknown);
  743.         }
  744. }
  745.  
  746.  
  747.  
  748.  
  749.  
  750. CONST
  751.     kLongIsHandle == 1;
  752.     kLongIsAppFilePtr == 2;
  753.     kLongIsMacFileRef == 3;
  754.     kLongIsTFile == 4;
  755.  
  756. pascal void OpenTreeDoc( longint data, integer datakind)
  757. VAR  
  758.         aTreeDoc    : TTreePrintDocument;
  759.         aFile    : TFile;
  760.         fref    : integer;
  761.         Handle        hData, hParams;
  762.         p            : CharsPtr;
  763.         
  764.         pascal void ReadDataFile( integer fref)
  765.         VAR    numChars    : longint;
  766.                 err    : integer;
  767.         {
  768.             FailOSErr(GetEOF(fref, numChars));    
  769.             hData= NewHandle( numChars+1);    
  770.             FailNIL( hData);
  771.             HLock( hData);
  772.             err= FSRead(fref, numChars, (*hData));
  773.             longint(p)= longint((*hData)) + numChars;  
  774.             (*p)[0]= ((char)(0)); // ?? NULL terminator...!! yes, for hcRead routines 
  775.             HUnlock(hData);
  776.             FailOSErr( err);
  777.             err= FSClose(fref);
  778.         }
  779.         
  780. {
  781.         switch (datakind) {
  782.             case kLongIsHandle:
  783.                 hData= Handle(data);
  784.             
  785.             kLongIsTFile: {
  786.                 longint(aFile)= data;
  787.                 FailOSErr(aFile->OpenFile());
  788.                  ReadDataFile( aFile->fDataRefNum);
  789.                 FailOSErr(aFile->CloseFile());
  790.                 }
  791.                 
  792.             kLongIsAppFilePtr: {
  793.                 /*----
  794.                 AppFilePtr        anAppFilePtr;
  795.                 longint(anAppFilePtr)= data;
  796.                 FailOSErr( FSOpen(anAppFilePtr->fName, anAppFilePtr->vRefNum, fref)); 
  797.                  ReadDataFile( fref);
  798.                 ----*/
  799.                 }
  800.                 
  801.             kLongIsMacFileRef: {
  802.                 ReadDataFile( data);
  803.                 }
  804.             
  805.             Otherwise
  806.                 FailOSErr( -1); //?
  807.             }
  808.  
  809.         New(aTreeDoc);
  810.         FailNIL(aTreeDoc);
  811.         aTreeDoc->ITreePrintDocument(kPrintClipType, hData, NULL, NIL/*itsFile*/);
  812.         
  813.         switch (datakind) {
  814.             kLongIsMacFileRef,
  815.             kLongIsAppFilePtr: hData= DisposeIfHandle( hData);
  816.             }
  817.             
  818.         gSeqAppApplication->OpenNewDocument(aTreeDoc); //finish up
  819. }
  820.  
  821.  
  822.  
  823.  
  824. pascal void TSeqAppApplication::OpenOld(CommandNumber itsOpenCommand, TList aFileList)
  825.          // override 
  826. //override to import alien sequences into current project doc
  827. //handle std open command only, to import alien TEXT seq files
  828. var
  829.         integer        i, nfiles, fref, rezref, kind, format, err;
  830.         fndrInfo    : FInfo;
  831.         aWind            : TWindow;
  832.         aAlnDoc        : TAlnDoc;
  833.         Boolean        wantAppend;
  834.         aFile            : TFile;
  835.         clName        : MAName;
  836. {
  837.     nfiles= aFileList->GetSize();
  838.     aAlnDoc= NULL;
  839.     
  840.     FOR i= 1 to nfiles){
  841.     aFile= TFile(aFileList->At(i));   
  842.  
  843.     if ((aFile->fFileType == 'PICT')) {  
  844.         //- inherited::OpenOld( cOpenPict, aFileList); 
  845.         FailOSErr(-1); //not ready yet...
  846.         }        
  847.     else if ((itsOpenCommand == cOpenTree) && (aFile->fFileType == 'TEXT'))   
  848.         OpenTreeDoc( longint(aFile), kLongIsTFile) 
  849.         
  850.     else if ((itsOpenCommand in [cOpen,cOpenProj,cFinderOpen]) 
  851.      && (aFile->fFileType == 'TEXT')) {  
  852.         wantAppend= shiftKeyIsDown;
  853.         
  854.          if ((itsOpenCommand!=cFinderOpen)) CASE gSFGetKind OF
  855.             kSFGetText: {
  856.                  inherited::OpenOld(cOpenText, aFileList); exit(OpenOld);
  857.                  }
  858.             kSFGetTree: {
  859.                 OpenTreeDoc( longint( aFile), kLongIsTFile); 
  860.                 exit(OpenOld); //!? should be goto next file !
  861.                 }
  862.             kSFGetBasesAppend: wantAppend= TRUE;
  863.             kSFGetBases: ;
  864.             }
  865.          
  866.         if (optionKeyIsDown) {
  867.             inherited::OpenOld(cOpenText, aFileList);    exit(OpenOld);
  868.             }            
  869.         else if (TestForSeqFile( aFile)) {
  870.             //? Do we want to append to current project ?
  871.             aWind= this->GetFrontWindow(); //GetActiveWindow;  
  872.             if ((aWind!=NULL) && (aWind->fDocument != NULL)) {
  873.                 aWind->fDocument->GetClassName( clName);
  874.                 UprMAName(clName);
  875.                 if (clName == 'TALNDOC')) {
  876.                     aAlnDoc= TAlnDoc(aWind->fDocument);
  877.                     if (aAlnDoc->ListIsEmpty()) { 
  878.                         aAlnDoc->CloseAndFree();
  879.                         aAlnDoc= NULL;
  880.                         }
  881.                     }
  882.                 }
  883.                 
  884.             if ((aAlnDoc!=NULL) && wantAppend) {
  885.                 // import into current proj 
  886.                 gSeqListDoc= aAlnDoc; //!? do we need this holdover 
  887.                 FailOSErr(aFile->OpenFile());
  888.               aAlnDoc->AppendRead(aFile->fDataRefNum);
  889.                 FailOSErr(aFile->CloseFile());
  890.                 aAlnDoc->ShowReverted();
  891.                 }            else {
  892.                 inherited::OpenOld(cOpenProj, aFileList); exit(OpenOld);
  893.                 }
  894.             }            
  895.         else {
  896.             inherited::OpenOld(cOpenText, aFileList); exit(OpenOld);
  897.             }            
  898.         }    else {
  899.         inherited::OpenOld(itsOpenCommand, aFileList); exit(OpenOld);
  900.         }
  901.     } //for each file
  902.     
  903. }
  904.  
  905. /*******
  906. pascal void TSeqAppApplication::OpenNewDocument(TDocument VAR aNewDocument)
  907. VAR
  908.         FailInfo        fi;
  909.         Str255        newTitle;
  910.         TWindow        aWindow;
  911.  
  912.     pascal void HdlOpenNew(integer error,  long message)
  913.     {
  914.         FreeIfObject(aNewDocument);
  915.         aNewDocument = NULL;
  916.         FailNewMessage(error, message, messageNewFailed);
  917.     }
  918.  
  919. {
  920. /*-------
  921.     THIS IS TApplication->OpenNew(itsCommandNumber) WITHOUT THIS
  922.     Prelim DoMakeDocument SO I CAN Create && Initialize Subdocs properly
  923.     from other Documents
  924.     .....
  925.     aNewDocument = NULL;
  926.     aNewDocument = DoMakeDocument(KindOfDocument(itsCommandNumber, NULL));
  927. -------*/
  928.     CatchFailures(fi, HdlOpenNew);
  929.  
  930.     aNewDocument->DoInitialState();
  931.     aNewDocument->DoMakeViews(kForDisplay);
  932.     aNewDocument->DoMakeWindows();
  933.  
  934.     aNewDocument->UntitledName(newTitle);
  935.     // For MacApp 1.1, newTitle should be always != '' 
  936.     if (newTitle != '')
  937.         aNewDocument->SetTitle(newTitle)
  938.     else if ((aNewDocument->fWindowList != NULL) && (aNewDocument->fWindowList.GetSize > 0))
  939.     // Grope, grope, grope 
  940.         {                                            // must set fTitle field anyways 
  941.         aWindow = TWindow(aNewDocument->fWindowList->First());
  942.  
  943.         aWindow->GetTitle(newTitle);
  944.         Handle(aNewDocument->fTitle) = DisposeIfHandle(aNewDocument->fTitle);
  945.         aNewDocument->fTitle = NewString(Copy(newTitle, aWindow->fPreDocname, length(newTitle) -
  946.                                            aWindow->fConstTitle));
  947.         FailNil(aNewDocument->fTitle);
  948.         }
  949.  
  950.     AddDocument(aNewDocument);
  951.     FailSpaceIsLow();                                     // Fail if document leaves us with no room 
  952.     // Don't attempt to show the windows until we're sure we won't fail 
  953.     aNewDocument->ShowWindows();
  954.     Success(fi);
  955. }
  956. ******/
  957.  
  958.  
  959.  
  960. pascal TDocument TSeqAppApplication::DoMakeDocument(CommandNumber itsCommandNumber, 
  961.                                                     TFile itsFile) // override 
  962. VAR
  963.         aAlnDoc                : TAlnDoc;
  964.         aTextDocument    : TTextDocument;
  965.         aHelpDocument    : THelpDocument;
  966.         aGopherDocument    : TGopherDocument;
  967.         aTreeDoc    : TTreePrintDocument;
  968.         numChars    :  longint;
  969.         TColorPrefDocument        aColorPrefDocument;
  970. {
  971.      switch (itsCommandNumber) {
  972.             
  973.         cHelpCommand,
  974.         cOpenHelp: {
  975.             New(aHelpDocument);
  976.             FailNIL(aHelpDocument);
  977.             aHelpDocument->IHelpDocument( (*gHelpFile)^, gAppWDRef);
  978.             DoMakeDocument = aHelpDocument;
  979.             }
  980.  
  981.         cOpenNAColors,
  982.         cOpenAAColors: {
  983.             New(aColorPrefDocument);
  984.             FailNIL(aColorPrefDocument);
  985.             if itsCommandNumber == cOpenAAColors
  986. ) aColorPrefDocument->IColorPrefDocument( itsFile, kAmino)
  987.                 else aColorPrefDocument->IColorPrefDocument( itsFile, kDNA);
  988.             DoMakeDocument = aColorPrefDocument;
  989.             }
  990.  
  991.         cOpenTree: {
  992.             New(aTreeDoc);
  993.             FailNIL(aTreeDoc);
  994.             aTreeDoc->ITreePrintDocument(kPrintClipType, NULL, NIL, itsFile);
  995.             DoMakeDocument = aTreeDoc;
  996.             }
  997.  
  998.         cNewGopherFolder,      // data is in gGopherData 
  999.         cOpenGopherFolder,     // data is in gGopherFile 
  1000.         cNewGopher, cOpenGopher: {
  1001.         
  1002.             New(aGopherDocument);
  1003.             FailNIL(aGopherDocument);
  1004.             if ((itsCommandNumber == cNewGopherFolder)) {
  1005.                 //! set aGopherDocument->Untitled() to name it gGopherTitle 
  1006.                 aGopherDocument->IGopherDocument( gGopherData, gGopherTitle, gCurrentGopher, itsFile);
  1007.                 }            else if ((itsCommandNumber == cOpenGopherFolder)) {
  1008.                 aGopherDocument->IGopherDocument( NULL, gGopherTitle, NULL, itsFile);
  1009.                 }            else {
  1010.                 aGopherDocument->IGopherDocument( NULL, NIL, NULL, itsFile);
  1011.                 }
  1012.             DoMakeDocument = aGopherDocument;
  1013.             }
  1014.             
  1015.             
  1016.         cNewGopherText,        // data is in gGopherData 
  1017.         cOpenGopherText,    // data is in gGopherFile 
  1018.         cNewText, cOpenText: {
  1019.             New(aTextDocument);
  1020.             FailNIL(aTextDocument);
  1021.             aTextDocument->ITextDocument(itsFile, kTextScrapType, 0, 0);
  1022.             
  1023.             if ((itsCommandNumber == cNewGopherText)) {
  1024.                     // this is a mess ... need new textdoc type for gopher? -- display > 32K !?
  1025.                 numChars= GetHandleSize( gGopherData);
  1026.                 if (numChars > kUnlimited) {     
  1027.                     gApplication->ShowError(0, messageAlert + kFileTooBig);
  1028.                     numChars = kUnlimited;
  1029.                     /*--
  1030.                     if ((aTextDocument->fTitle!=NULL)) 
  1031.                             SetString( aTextDocument->fTitle, concat(aTextDocument.(*fTitle)^,'-Short'));
  1032.                     --*/
  1033.                     }
  1034.                 // set aTextDocument->Untitled() to gGopherTitle 
  1035.                 SetHandleSize(aTextDocument->fTextData.fChars, numChars);
  1036.                 FailMemError();
  1037.                 HLock( gGopherData);
  1038.                 HLock( aTextDocument->fTextData.fChars);
  1039.                 BLockMove( (*gGopherData), aTextDocument->fTextData.(*fChars), numChars);
  1040.                 HUnlock( gGopherData);
  1041.                 HUnlock( aTextDocument->fTextData.fChars);
  1042.                 }
  1043.                 
  1044.             DoMakeDocument = aTextDocument;
  1045.             }
  1046.             
  1047.             
  1048.         cNewDebug: if (gDebugDoc=NULL) {
  1049.             New(gDebugDoc);
  1050.             FailNIL(gDebugDoc);
  1051.             gDebugDoc->ITextDocument(itsFile, kTextScrapType, 0, 0);
  1052.             DoMakeDocument = gDebugDoc;
  1053.             }
  1054.                                 
  1055.         /*cNew: begin
  1056.             -- ? variable action
  1057.             end(); */
  1058.         /*cOpen: begin
  1059.             -- variable action
  1060.             ++ caught by OpenOld if ftype == TEXT
  1061.             end();*/
  1062.         
  1063.         otherwise begin //== cNewProj/cOpenProj, cNew/cOpen
  1064.             New(aAlnDoc);
  1065.             FailNIL(aAlnDoc);
  1066.             aAlnDoc->IAlnDoc( itsFile);
  1067.             DoMakeDocument = aAlnDoc;
  1068.             }
  1069.             
  1070.         }
  1071. }
  1072.  
  1073.  
  1074. pascal void TSeqAppApplication::AboutToLoseControl(Boolean convertClipboard) // override 
  1075. {
  1076.     inherited::AboutToLoseControl(convertClipboard);
  1077. }
  1078.  
  1079.  
  1080.     
  1081. pascal void TIUBWindow::SetPrefID(void)    
  1082. {
  1083.     gPrefWindID= kIUBcodeWindID; gPrefWindName= 'TIUBWindow';
  1084. }
  1085.  
  1086. pascal void TAAWindow::SetPrefID(void)    
  1087. {
  1088.     gPrefWindID= kAAcodeWindID; gPrefWindName= 'TAAWindow';
  1089. }
  1090.  
  1091.  
  1092. pascal void TSeqAppApplication::DoMenuCommand(aCommandNumber:CommandNumber); // override 
  1093.  
  1094.     pascal void PrefsDialog(void)
  1095.     VAR aWind    : TPrefsDialog; boolean isNowOpen,
  1096.         pascal void checkOpenWind( TWindow aWind)
  1097.         {
  1098.             if (Member(TObject(aWind), TPrefsDialog)) { 
  1099.                 aWind->Select(); isNowOpen= TRUE;
  1100.                 }
  1101.         }
  1102.     {
  1103.         isNowOpen= FALSE;
  1104.         ForAllWindowsDo(checkOpenWind);
  1105.         if (!isNowOpen) {
  1106.             aWind = TPrefsDialog(gViewServer->NewTemplateWindow(kPrefsDialogID, NULL));
  1107.             FailNIL(aWind);          
  1108.             aWind->IPrefsDialog();
  1109.             aWind->ShowReverted(); 
  1110.             aWind->Open(); 
  1111.             aWind->Select();     
  1112.             }
  1113.     }
  1114.     
  1115.     pascal void HelpDialog(void)
  1116.     VAR 
  1117.             isNowOpen    : boolean;
  1118.             THelpDocument        aHelpDocument ;
  1119.             
  1120.         pascal void checkOpenDocs( TDocument aDoc)
  1121.         {
  1122.             if (Member(TObject(aDoc), THelpDocument)) { 
  1123.                 TWindow(aDoc->fWindowList->First()).Select; 
  1124.                 isNowOpen= TRUE;
  1125.                 }
  1126.         }
  1127.     {
  1128.         isNowOpen= FALSE;
  1129.         ForAllDocumentsDo(checkOpenDocs);
  1130.         if (!isNowOpen) {
  1131.             New(aHelpDocument);
  1132.             FailNIL(aHelpDocument);
  1133.             aHelpDocument->IHelpDocument( (*gHelpFile)^, gAppWDRef);
  1134.             this->OpenNewDocument( aHelpDocument);
  1135.             }
  1136.     }
  1137.  
  1138. /******
  1139.     pascal void ShowIUBDlog(void)
  1140.     VAR aWind    : TIUBWindow; boolean isNowOpen,
  1141.     
  1142.         pascal void checkOpenWind( TWindow aWind)
  1143.         {
  1144.             if (Member(TObject(aWind), TIUBWindow)) { 
  1145.                 aWind->Select(); isNowOpen= TRUE;
  1146.                 }
  1147.         }
  1148.     {
  1149.         isNowOpen= FALSE;
  1150.         ForAllWindowsDo(checkOpenWind);
  1151.         if (!isNowOpen) {
  1152.             aWind = TIUBWindow(gViewServer->NewTemplateWindow(kIUBcodeWindID, NULL));
  1153.             FailNIL(aWind);          
  1154.             aWind->IPrefWindow(); 
  1155.             aWind->ShowReverted();   
  1156.             aWind->Open();  
  1157.             }
  1158.     }
  1159.     *****/
  1160.     
  1161.     pascal void ShowIUBDlog(void)
  1162.     VAR 
  1163.             isNowOpen    : boolean;
  1164.             TColorPrefDocument        aColorPrefDocument ;
  1165.             
  1166.         pascal void checkOpenDocs( TDocument aDoc)
  1167.         {
  1168.             if (Member(TObject(aDoc), TColorPrefDocument)) 
  1169.              if (TColorPrefDocument(aDoc).fBaseKind != kAmino)
  1170.               { 
  1171.                 TWindow(aDoc->fWindowList->First()).Select; 
  1172.                 isNowOpen= TRUE;
  1173.                 }
  1174.         }
  1175.     {
  1176.         isNowOpen= FALSE;
  1177.         ForAllDocumentsDo(checkOpenDocs);
  1178.         if (!isNowOpen) {
  1179.             New(aColorPrefDocument);
  1180.             FailNIL(aColorPrefDocument); 
  1181.             aColorPrefDocument->IColorPrefDocument( NULL/*itsFile*/, kDNA);
  1182.             this->OpenNewDocument( aColorPrefDocument);
  1183.             }
  1184.     }
  1185.  
  1186. /******
  1187.     pascal void ShowAADlog(void)
  1188.     VAR aWind    : TAAWindow; boolean isNowOpen,
  1189.     
  1190.         pascal void checkOpenWind( TWindow aWind)
  1191.         {
  1192.             if (Member(TObject(aWind), TAAWindow)) {  
  1193.                 aWind->Select(); isNowOpen= TRUE;
  1194.                 }
  1195.         }
  1196.     {
  1197.         isNowOpen= FALSE;
  1198.         ForAllWindowsDo(checkOpenWind);
  1199.         if (!isNowOpen) {
  1200.             aWind = TAAWindow(gViewServer->NewTemplateWindow(kAAcodeWindID, NULL));
  1201.             FailNIL(aWind);          
  1202.             aWind->IPrefWindow(); 
  1203.             aWind->ShowReverted();   
  1204.             aWind->Open();  
  1205.             }
  1206.     }
  1207. ******/
  1208.  
  1209.     pascal void ShowAADlog(void)
  1210.     VAR 
  1211.             isNowOpen    : boolean;
  1212.             TColorPrefDocument        aColorPrefDocument ;
  1213.             
  1214.         pascal void checkOpenDocs( TDocument aDoc)
  1215.         {
  1216.             if (Member(TObject(aDoc), TColorPrefDocument)) 
  1217.              if (TColorPrefDocument(aDoc).fBaseKind == kAmino)
  1218.                 { 
  1219.                 TWindow(aDoc->fWindowList->First()).Select; 
  1220.                 isNowOpen= TRUE;
  1221.                 }
  1222.         }
  1223.     {
  1224.         isNowOpen= FALSE;
  1225.         ForAllDocumentsDo(checkOpenDocs);
  1226.         if (!isNowOpen) {
  1227.             New(aColorPrefDocument);
  1228.             FailNIL(aColorPrefDocument); 
  1229.             aColorPrefDocument->IColorPrefDocument( NULL/*itsFile*/, kAmino);
  1230.             this->OpenNewDocument( aColorPrefDocument);
  1231.             }
  1232.     }
  1233.     
  1234.  
  1235.  
  1236. {
  1237.     switch (aCommandNumber) {
  1238.     
  1239.         PrefsDialog        cPrefsDialog;
  1240.  
  1241.         cHelpCommand,
  1242.         cOpenHelp    : HelpDialog;  
  1243.         
  1244.         cIUBcodes    : ShowIUBDlog;
  1245.         cAAcodes    : ShowAADlog;
  1246.         
  1247.         OpenNewChild        cAddChildCmd;
  1248.         OpenEditChild        cRemoveChildCmd; //RemoveChildren;
  1249.  
  1250.         cGopher        : OpenGopher;  
  1251.         OpenGopherPrefs        cGopherPrefs;
  1252.  
  1253.         cMailPref    : OpenMailPref;
  1254.         OpenCheckmail        cCheckMail;
  1255.         
  1256.         cSendMail, cBugMail, cGBFetch, cEMBLFetch, 
  1257.         cUHServer : MailTo(aCommandNumber);         
  1258.         
  1259.         default:
  1260.             inherited::DoMenuCommand(aCommandNumber);
  1261.         }
  1262. }
  1263.  
  1264.  
  1265. pascal void TSeqAppApplication::DoSetupMenus(void) // override 
  1266. VAR
  1267.     Boolean        lowSpace;
  1268. {
  1269.     inherited::DoSetupMenus();
  1270.     
  1271.     lowSpace = MemSpaceIsLow;  
  1272.     Enable(cNewText, !lowSpace);
  1273.     Enable(cOpenText, !lowSpace);
  1274.     Enable(cOpenHelp, !lowSpace);
  1275.     
  1276.     //some help dialogs/picts...
  1277.     Enable( cIUBcodes, TRUE);
  1278.     Enable( cAAcodes, TRUE);
  1279.     Enable( cPrefsDialog, TRUE);
  1280.  
  1281.     Enable( cAddChildCmd, TRUE);
  1282.     if ((gChildCommandList!=NULL))
  1283.         Enable( cRemoveChildCmd, gChildCommandList.GetSize>0);
  1284.  
  1285.     Enable( cMailPref, TRUE); 
  1286.     //! all of these depend on MacTCP 
  1287.     Enable( cCheckMail, gTCPIsInstalled); 
  1288.     Enable( cSendMail, gGoodMac && gTCPIsInstalled); 
  1289.     Enable( cGopher, gTCPIsInstalled); 
  1290.     Enable( cNewGopher, gTCPIsInstalled && !lowSpace);
  1291.     Enable( cGopherPrefs, TRUE);
  1292. //-    Enable( cFileTransfer, gTCPIsInstalled);  
  1293.     Enable( cBugMail, gGoodMac && gTCPIsInstalled);
  1294.     Enable( cGBFetch, gGoodMac && gTCPIsInstalled); 
  1295.     Enable( cEMBLFetch, gGoodMac && gTCPIsInstalled); 
  1296.     Enable( cUHServer, gGoodMac && gTCPIsInstalled); 
  1297. }
  1298.  
  1299.  
  1300.  
  1301.  
  1302.  
  1303.  
  1304. pascal void TSeqAppApplication::ShowError(OSErr error,  LongInt message) // override 
  1305. CONST
  1306.         kMsgCmdErr            == messageCommandError / 0x10000;
  1307.         kMsgAlert                == messageAlert / 0x10000;
  1308.         kMsgLookup            == messageLookup / 0x10000;
  1309.         kMsgAltRecov        == messageAlternateRecovery / 0x10000;
  1310. TYPE
  1311.         Converter            == RECORD CASE Boolean OF
  1312.                 TRUE: (LongInt message)
  1313.                 FALSE: (short hiWd, loWd)
  1314.                 }
  1315. VAR
  1316.         Converter        c;
  1317.         short        alertID;
  1318.         Boolean        genericAlert;
  1319.         Str255        opString;
  1320. {
  1321.     if ((message == msgMyError) /*? or err == errMyError*/) {
  1322.         /*------
  1323.         c.message = message;
  1324.         if ((c.hiWd == kMsgCmdErr))    {
  1325.             alertID = phCommandError;
  1326.             CommandToName(c.loWd, opString);
  1327.             }
  1328.         ----*/
  1329.         //- alertID = phGenError; 
  1330.         //- alertID = phUknownErr; 
  1331.         alertID = phCommandError;
  1332.         genericAlert = TRUE;
  1333.         opString = '';
  1334.         StdAlert(alertID);
  1335.         gInhibitNestedHandling = FALSE;                     
  1336.         if (genericAlert) ResetAlrtStage;
  1337.         }    else
  1338.         inherited::ShowError(error,  message);
  1339. }
  1340.  
  1341.  
  1342.  
  1343.  
  1344.  
  1345.  
  1346.  
  1347.  
  1348.  
  1349. /*****
  1350. // THandle1HighlevelEvents -----------------------------
  1351.  
  1352.     THandle1HighlevelEvents    == OBJECT (TEventHandler)
  1353.         pascal void THandle1HighlevelEvents::IEventHandler(TEventHandler itsNextHandler) 
  1354.             // override 
  1355.         pascal Boolean THandle1HighlevelEvents::DoHandleEvent( EventRecordPtr nextEvent, 
  1356.                 TCommand VAR commandToPerform) // override 
  1357.         }
  1358.  
  1359. pascal void THandle1HighlevelEvents::IEventHandler(TEventHandler itsNextHandler) 
  1360.         // override 
  1361. {
  1362.     inherited::IEventHandler(itsNextHandler);
  1363. }
  1364.  
  1365. pascal Boolean THandle1HighlevelEvents::DoHandleEvent( EventRecordPtr nextEvent, 
  1366.         TCommand VAR commandToPerform) // override 
  1367. VAR
  1368.     theErr:OSErr;
  1369. {
  1370.  
  1371.     if ((nextEvent->what == kHighLevelEvent)) {
  1372.         DoHandleEvent= TRUE;
  1373.         //-- this->SetupTheMenus(); 
  1374.         theErr= AEProcessAppleEvent((*nextEvent));
  1375.         if ((theErr!=noErr) && (theErr != errAEEventNotHandled))
  1376.             then FailOSErr(theErr);
  1377.         }    else
  1378.         DoHandleEvent= FALSE;
  1379.         
  1380. }
  1381. ******/
  1382.  
  1383.  
  1384.  
  1385.  
  1386. //    TPrefsDialog -------------------------- 
  1387.  
  1388.  
  1389. pascal void TPrefsDialog::IPrefsDialog(void)
  1390. {    
  1391.     IPrefWindow();
  1392.     fWantSave= TRUE;
  1393. /*----------
  1394. VAR
  1395.     TButton        aSendBut;
  1396.     aFrom        : TEditText;
  1397. {    
  1398.  
  1399.     fPrefsDialogView= TPrefsDialogView(FindSubView('View'));
  1400.     if ((fPrefsDialogView!=NULL)) fPrefsDialogView->IPrefsDialogView();
  1401.     fTo             = TEditText(FindSubView('eTo:'));  
  1402.   fCc           = TEditText(FindSubView('eCc:'));  
  1403.   fSubject    = TEditText(FindSubView('eSb:'));  
  1404.   aFrom            = TEditText(FindSubView('eFm:'));  
  1405.     if ((aFrom!=NULL)) aFrom->SetText( gMyMailAddress, TRUE);
  1406.     aSendBut= TButton(FindSubView('OKAY'));
  1407.     if ((aSendBut!=NULL) then aSendBut->fDefaultChoice= mSendit;
  1408. --------*/
  1409. }
  1410.  
  1411.  
  1412. pascal void TPrefsDialog::DoEvent(EventNumber eventNumber, 
  1413.                                             TEventHandler        source; TEvent event) /* override */ 
  1414. {
  1415.     inherited::DoEvent(eventNumber, source, event);
  1416.     /*-----
  1417.     switch (eventNumber) {
  1418.         Sendit        mSendit;
  1419.         case mCheckboxHit: 
  1420.           if ((fUnlockTexts!=NULL) && (source=fUnlockTexts)) {
  1421.                 if (fUnlockTexts->IsOn()) UnlockTexts
  1422.                 else RelockTexts;
  1423.                 }
  1424.  
  1425.         Otherwise
  1426.             inherited::DoEvent(eventNumber, source, event);
  1427.         }
  1428.     ------*/
  1429. }
  1430.  
  1431.  
  1432. pascal void TPrefsDialog::SetPrefID(void) /* override */ 
  1433. {
  1434.     gPrefWindID= kPrefsDialogID; gPrefWindName= 'TPrefsDialog';
  1435. }
  1436.  
  1437.  
  1438.  
  1439.  
  1440.  
  1441. // TColorPrefDocument ---------------------
  1442.  
  1443.  
  1444.  
  1445. pascal void TColorText::InstallColor(RGBColor theColor, Boolean redraw) // override 
  1446. /*
  1447.   ((CRGBColor &) fTextStyle.tsColor) == theColor;
  1448.     if (redraw) this->DrawContents();
  1449. */  
  1450. {
  1451.     if ((fDrawingEnvironment!=NULL)) {
  1452.         if (TColorPrefDocument(fDocument).fSwapBackground->IsOn())) 
  1453.             fDrawingEnvironment->fBackgroundColor= theColor
  1454.         else  
  1455.             fDrawingEnvironment->fForegroundColor= theColor;
  1456.         }
  1457.     
  1458.     inherited::InstallColor( theColor, redraw);
  1459. }
  1460.  
  1461.         
  1462. pascal void TColorPrefDocument::IColorPrefDocument( TFile itsFile, Integer baseKind)
  1463. VAR
  1464.     OSType        fileType; 
  1465.     ch     : char;
  1466. {
  1467.     fBaseKind= baseKind;
  1468.     fDoSetGlobals= False;
  1469.     fSwapBack= gSwapBackground;
  1470.     fSwapBackground= NULL;
  1471.     fDescription= '';
  1472.     if (baseKind == kAmino) then {
  1473.         fWindID = kAAColorView;
  1474.         fileType= kAAColorType;
  1475.         }    else {
  1476.         fWindID = kNAColorView;
  1477.         fileType= kNAColorType;
  1478.         }
  1479.     gNoColor.red= -123;
  1480.     gNoColor.blue= 456;
  1481.     gNoColor.green= -789;
  1482.     gNoViewID= '????';
  1483.     FOR ch= ' ' TO '~'){
  1484.         fColors[ch]    = gNoColor;
  1485.         fViewIDS[ch]= gNoViewID;
  1486.         }
  1487.         
  1488.     if (itsFile == NULL)) //? don't need ?
  1489.         itsFile= NewFile(fileType, kSAppSig, kUsesDataFork, kUsesRsrcFork, !kDataOpen, !kRsrcOpen);
  1490.     IFileBasedDocument(itsFile, fileType);
  1491.     fSavePrintInfo= FALSE; 
  1492. }
  1493.  
  1494. pascal void TColorPrefDocument::FreeData(void)
  1495. {
  1496.  
  1497. }
  1498.  
  1499.  
  1500. pascal void TColorPrefDocument::Free(void) // override 
  1501. {
  1502.     FreeData();
  1503.     inherited::Free();
  1504. }
  1505.  
  1506.  
  1507. pascal void TColorPrefDocument::SetGlobals(void) 
  1508. VAR  ch: char;
  1509. {
  1510.         //install colors only at close ?? -- need also to initialize gAAcolors && gNAcolors !
  1511.         //need Okay/Cancel buttons on this window/doc ??
  1512.     FOR ch= 'a' TO 'z')fColors[ch]= fColors[UprChar(ch)]; //!?!
  1513.     if ((fBaseKind == kAmino))
  1514.         BlockMove( &fColors, &gAAcolors, sizeof(colorsArray)) 
  1515.     else
  1516.         BlockMove( &fColors, &gNAcolors, sizeof(colorsArray)); 
  1517.     //-- not ready -- background not displaying...
  1518.     if ((fSwapBackground!=NULL)) gSwapBackground= fSwapBackground->IsOn();
  1519. }
  1520.  
  1521.  
  1522. pascal void TColorPrefDocument::Close(void) /* override */ 
  1523. {
  1524.     if ((fDoSetGlobals)) SetGlobals;        
  1525.   inherited::Close();
  1526. }
  1527.  
  1528.  
  1529.  
  1530. pascal void TColorPrefDocument::DoHitLetter(TStaticText theLet)
  1531. VAR
  1532.         ch    : char;
  1533.         OSType        id ;
  1534.         Point        where;
  1535.         Str63        prompt;
  1536.         RGBColor        outColor;
  1537. {                
  1538.     id= theLet->fIdentifier;
  1539.     for ch= ' ' to '~' do if (fViewIDs[ch] == id) then begin
  1540.         SetPt( where, 0, 0);
  1541.         prompt= '1'; 
  1542.         prompt[1]= ch;
  1543.         prompt= concat('Choose color for "',prompt,'"');
  1544.         outColor= fColors[ch];
  1545.         if (GetColor( where, prompt, outColor, outColor)) {
  1546.             fColors[ch]= outColor; //-- save color
  1547.             this->Changed( 1, this); //-- mark fDoc as dirty/need save
  1548.             fDoSetGlobals= True;   //-- install color in any global color set if needed 
  1549.             //- theLet->fTextStyle.tsColor= outColor;  theLet->ForceRedraw();
  1550.             TColorText(theLet)->InstallColor(outColor, kRedraw); 
  1551.             }
  1552.         LEAVE(); 
  1553.         }
  1554. }
  1555.  
  1556.  
  1557. pascal void TColorPrefDocument::DoMakeViews(Boolean forPrinting) // override 
  1558. VAR
  1559.         aWindow    : TWindow;
  1560.         ch     : char;
  1561.         RGBColor        aColor;
  1562.         TCluster        aColorGroup;
  1563.         TEditText        aDescText;
  1564.         aStr    : Str255;
  1565.         
  1566.     pascal Boolean equalColors( RGBColor a, b)
  1567.     {
  1568.         equalColors= (a.red == b.red) && (a.green == b.green) && (a.blue == b.blue);
  1569.     }
  1570.     
  1571.     pascal void collectLetters(TColorText letter)
  1572.     VAR   
  1573.             ch     : char;
  1574.             Str255        aStr;
  1575.             RGBColor        aColor;
  1576.     {
  1577.         letter->GetText(aStr); 
  1578.         ch= aStr[1];
  1579.         fViewIDs[ch]= letter->fIdentifier;
  1580.         //- aColor= letter->fTextStyle.tsColor;
  1581.         aColor= fColors[ch];
  1582.         letter->InstallColor( aColor, kDontRedraw); 
  1583.     }
  1584.         
  1585. {
  1586.     aWindow = gViewServer->NewTemplateWindow(fWindID, this);
  1587.     FailNil(aWindow);
  1588.     
  1589.     fColorPrefWind= TColorPrefWind(aWindow);
  1590.     fColorPrefWind->fDocument= this;
  1591.  
  1592.     aStr= fDescription;
  1593.     aDescText= TEditText(aWindow->FindSubView('desc')); 
  1594.     if (aDescText!=NULL)) aDescText->SetText( aStr, kDontRedraw);
  1595.     fSwapBackground= TCheckBox(aWindow->FindSubView('back')); 
  1596.     FailNIL(fSwapBackground);
  1597.     fSwapBackground->SetState( fSwapBack, kDontRedraw);
  1598.     
  1599.     aColorGroup= TCluster(aWindow->FindSubView('cclu')); 
  1600.     if (gConfiguration.hasColorQD) {
  1601.         FailNil(aColorGroup);
  1602.              //set unknowns to usable color
  1603.         FOR ch= ' ' to '~'){
  1604.             aColor= fColors[ch];
  1605.             if (equalColors( aColor, gNoColor)) {
  1606.                 if (fBaseKind == kAmino)) fColors[ch]= gAAcolors[ch]
  1607.                 else fColors[ch]= gNAcolors[ch];
  1608.                 }
  1609.             }
  1610.         aColorGroup->EachSubView(collectLetters);
  1611.         }
  1612.     
  1613.     //!? call SetGlobals here if data was read from disk ?
  1614.     if (fDoSetGlobals) {
  1615.         SetGlobals(); 
  1616.         fDoSetGlobals= False; 
  1617.         }
  1618.  
  1619.     //? may need to show TEView in PrintView... ?
  1620.     this->ShowReverted();   
  1621. }
  1622.  
  1623.  
  1624. pascal void TColorPrefDocument::UntitledName(Str255 VAR noName) // override 
  1625. //called AFTER .Idoc and .MakeViews 
  1626. {
  1627.     inherited::UntitledName( noName);
  1628.     /*---
  1629.     noName= Concat(fSeq->fName,' PrettyPrint'); 
  1630.     if ((fWindowList != NULL) && (fWindowList.GetSize > 0))         
  1631.         TWindow(fWindowList->First())->SetTitle(noName);
  1632.     ---*/
  1633. }
  1634.  
  1635.  
  1636. pascal TFile TColorPrefDocument::DoMakeFile(itsCommandNumber:CommandNumber); // override 
  1637. {
  1638.     DoMakeFile= NewFile(fScrapType, gApplication->fCreator, kUsesDataFork, kUsesRsrcFork, 
  1639.                                                 !kDataOpen, !kRsrcOpen);
  1640. }
  1641.  
  1642.  
  1643.  
  1644. pascal void TColorPrefDocument::DoNeedDiskSpace(TFile itsFile,
  1645.                                                             long VAR dataForkBytes, rsrcForkBytes)
  1646. VAR numLets: integer;                                                            
  1647. {
  1648.     //)!get Print record requirements 
  1649.     //- inherited::DoNeedDiskSpace(dataForkBytes, rsrcForkBytes); 
  1650.     
  1651.     numLets= ord('~') - ord(' ') + 1;
  1652.     rsrcForkBytes = rsrcForkBytes + numLets * (sizeof(TextStyle) /*+ Length(fontname)*/);
  1653. }
  1654.  
  1655. pascal void TColorPrefDocument::DoRead(aFile:TFile; Boolean forPrinting)
  1656. VAR
  1657.         saveMap     : integer;
  1658.         TextStyle        aTextStyle;
  1659.         integer        i, nColors;
  1660.         ch    : char;
  1661.         Handle        oldValue ;
  1662. {
  1663.     //-- inherited::DoRead(aRefNum, rsrcExists, forPrinting);)!read print info stuff
  1664.     if (aFile->HasRsrcFork()) {
  1665.         if (!aFile->IsRsrcForkOpen()) FailOSErr( aFile->OpenRsrcFork(fsRdPerm));
  1666.         saveMap= aFile->UseResource();
  1667.         
  1668.         /*! need also to read/write
  1669.             -- description string
  1670.             -- fSwapBackground.IsOn flag
  1671.         */
  1672.         oldValue= Get1Resource('STR ', 1);
  1673.         if (oldValue!=NULL) fDescription= (*StringHandle( oldValue))^;
  1674.         
  1675.         oldValue= Get1Resource('Flag', 1);
  1676.         if (oldValue!=NULL))    fSwapBack= Boolean((*oldValue)^);
  1677.  
  1678.         //- fHaveColors= GetTextStyleRsrc(aFile->fRsrcRefNum, theTextStyle, 1);
  1679.         nColors= Count1Resources('TxSt');
  1680.         for i= 1 to nColors do begin
  1681.             ch= ((char)( i-1+ord(' ')));
  1682.             MAGetTextStyle(i, aTextStyle);  
  1683.             fColors[ch]= aTextStyle.tsColor;
  1684.             }
  1685.         if (nColors > 0) fDoSetGlobals= True;   //-- install color in any global color set if needed 
  1686.         
  1687.         UseResFile(saveMap);
  1688.         }
  1689. }
  1690.  
  1691.  
  1692. pascal void TColorPrefDocument::DoWrite(TFile aFile, Boolean makingCopy)
  1693. VAR
  1694.         TextStyle        aTextStyle;
  1695.         integer        i, saveMap ;
  1696.         ch    : char;
  1697.         TEditText        aDescText;
  1698.         Str255        aStr;
  1699.         StringHandle        aStrHand;
  1700.         Handle        oldValue;
  1701. {
  1702.     /*- inherited::DoWrite(aRefNum, makingCopy);     --)NO write print info stuff*/            
  1703.     aTextStyle= gAlnStyle; //?
  1704.     if (aFile->HasRsrcFork()) { //? if not, make one?
  1705.         if (!aFile->IsRsrcForkOpen()) FailOSErr( aFile->OpenRsrcFork(fsRdWrPerm));
  1706.         saveMap= aFile->UseResource();
  1707.         
  1708.         oldValue= Get1Resource('STR ', 1);
  1709.         if (oldValue!=NULL) {
  1710.             RmveResource(oldValue);
  1711.             DisposHandle(oldValue);
  1712.             }
  1713.         aDescText= TEditText(fColorPrefWind->FindSubView('desc')); 
  1714.         aDescText->GetText(aStr);
  1715.         aStrHand= NewString(aStr);
  1716.         AddResource( Handle(aStrHand), 'STR ', 1, '');
  1717.         SetResAttrs( Handle(aStrHand), resPurgeable);
  1718.         ChangedResource( Handle(aStrHand)); 
  1719.         
  1720.         oldValue= Get1Resource('Flag', 1);
  1721.         if (oldValue!=NULL) {
  1722.             RmveResource(oldValue);
  1723.             DisposHandle(oldValue);
  1724.             }
  1725.         oldValue= NewHandle(sizeof(SignedByte));
  1726.         (*oldValue)^= SignedByte(fSwapBackground->IsOn());
  1727.         AddResource( Handle(oldValue), 'Flag', 1, '');
  1728.         SetResAttrs( Handle(oldValue), resPurgeable);
  1729.         ChangedResource( Handle(oldValue)); 
  1730.         
  1731.         FOR ch= ' ' TO '~'){
  1732.             i= ord(ch) - ord(' ') + 1;
  1733.             aTextStyle.tsColor= fColors[ch];
  1734.             SetTextStyleRsrc(aFile->fRsrcRefNum, aTextStyle, i);
  1735.             }
  1736.             
  1737.         FailOSErr( aFile->UpdateResource());
  1738.         UseResFile(saveMap);
  1739.         }
  1740. }
  1741.  
  1742.  
  1743.  
  1744.  
  1745. // TColorPrefWind ------------------------- 
  1746.  
  1747. /*----
  1748. pascal void TColorPrefWind::IColorPrefWind(void)
  1749. {
  1750.     IPrefWindow();
  1751.     fWantSave= TRUE;
  1752. }
  1753. pascal void TColorPrefWind::SetPrefID(void) /* override */ 
  1754. {
  1755.     gPrefWindID= kColorPrefWindowRSRCID; gPrefWindName= 'TColorPrefWind';
  1756. }
  1757. ---*/
  1758.  
  1759. pascal void TColorPrefWind::DoEvent(EventNumber eventNumber, 
  1760.                                             TEventHandler        source; TEvent event) // override 
  1761. {
  1762.     switch (eventNumber) {
  1763.  
  1764.         mOKhit: {
  1765.             TColorPrefDocument(fDocument).fDoSetGlobals= True;
  1766.             CloseByUser();
  1767.             //- inherited::DoEvent(mDismiss,source, event); 
  1768.             }
  1769.         mCancelHit: {
  1770.             TColorPrefDocument(fDocument).fDoSetGlobals= False;
  1771.             CloseByUser();
  1772.             //- inherited::DoEvent(mDismiss,source, event); 
  1773.             }
  1774.         
  1775.         case mStaticTextHit:  
  1776.             TColorPrefDocument(fDocument)->DoHitLetter( TStaticText(source));
  1777.                 
  1778.         case mCheckboxHit: 
  1779.             if ((source == TColorPrefDocument(fDocument).fSwapBackground)) {
  1780.  
  1781.                 }            else 
  1782.                 inherited::DoEvent(eventNumber,source, event); 
  1783.  
  1784.         otherwise
  1785.             inherited::DoEvent(eventNumber,source, event); 
  1786.         }
  1787. }
  1788.  
  1789.